﻿using Coldairarrow.Business.DataView;
using Coldairarrow.Entity.DataView;
using Coldairarrow.Util;
using EFCore.Sharding;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.DataView
{
    [Route("/DataView/[controller]/[action]")]
    public class blade_visual_categoryController : BaseApiController
    {
        #region DI

        public blade_visual_categoryController(Iblade_visual_categoryBusiness blade_visual_categoryBus)
        {
            _blade_visual_categoryBus = blade_visual_categoryBus;
        }

        Iblade_visual_categoryBusiness _blade_visual_categoryBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<blade_visual_category>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _blade_visual_categoryBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<blade_visual_category> GetTheData(IdInputDTO input)
        {
            return await _blade_visual_categoryBus.GetTheDataAsync(input.id);
        }
        /// <summary>
        /// 查询所有(用于下拉显示)
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<blade_visual_category>> GetAllData()
        {
            return await _blade_visual_categoryBus.GetDataListAsync();
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(blade_visual_category data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);
                data.is_deleted = 0;

                await _blade_visual_categoryBus.AddDataAsync(data);
            }
            else
            {
                await _blade_visual_categoryBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _blade_visual_categoryBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}